USE [master]
GO

/****** Object:  Database [AppDB]    Script Date: 07/10/2013 18:46:56 ******/
IF  EXISTS (SELECT name FROM sys.databases WHERE name = N'AppDB')
DROP DATABASE [AppDB]
GO
/****** Object:  Database [AppDB]    Script Date: 07/10/2013 18:46:56 ******/
CREATE DATABASE [AppDB] ON  PRIMARY 
( NAME = N'AppDB_Data', FILENAME = N'C:\Database\AppDB_Database\AppDB_Data.mdf' , SIZE = 200640KB , MAXSIZE = UNLIMITED, FILEGROWTH = 16384KB )
 LOG ON 
( NAME = N'AppDB_Log', FILENAME = N'C:\Database\AppDB_Database\AppDB_log.LDF' , SIZE = 768KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO

USE [AppDB]
GO

IF  EXISTS (SELECT * FROM sys.schemas WHERE name = 'User')
DROP SCHEMA [User]
GO
CREATE SCHEMA [User]
GO

/****** Object:  Table [User].[Address]    Script Date: 07/10/2013 18:47:32 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[Address]') AND type in (N'U'))
DROP TABLE [User].[Address]
GO
CREATE TABLE [User].[Address](
	[AddressID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[AddressLine1] [nvarchar](60) NOT NULL,
	[AddressLine2] [nvarchar](60) NULL,
	[City] [nvarchar](30) NOT NULL,
	[StateProvinceID] [int] NOT NULL,
	[PostalCode] [nvarchar](15) NOT NULL,
 CONSTRAINT [PK_Address_AddressID] PRIMARY KEY CLUSTERED 
(
	[AddressID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [User].[AddressType]    Script Date: 07/10/2013 18:48:16 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[AddressType]') AND type in (N'U'))
DROP TABLE [User].[AddressType]
GO
CREATE TABLE [User].[AddressType](
	[AddressTypeID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_AddressType_AddressTypeID] PRIMARY KEY CLUSTERED 
(
	[AddressTypeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [User].[AddressMap]    Script Date: 07/10/2013 18:48:56 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[AddressMap]') AND type in (N'U'))
DROP TABLE [User].[AddressMap]
GO
CREATE TABLE [User].[AddressMap](
	[OwnerID] [int] NOT NULL,
	[AddressID] [int] NOT NULL,
	[AddressTypeID] [int] NOT NULL,
 CONSTRAINT [PK_AddressMap_OwnerID_AddressID_AddressTypeID] PRIMARY KEY CLUSTERED 
(
	[OwnerID] ASC,
	[AddressTypeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [User].[ContactType]    Script Date: 07/10/2013 18:49:30 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[ContactType]') AND type in (N'U'))
DROP TABLE [User].[ContactType]
GO
CREATE TABLE [User].[ContactType](
	[ContactTypeID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_ContactType_ContactTypeID] PRIMARY KEY CLUSTERED 
(
	[ContactTypeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [User].[CountryRegion]    Script Date: 07/10/2013 18:49:54 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[CountryRegion]') AND type in (N'U'))
DROP TABLE [User].[CountryRegion]
GO
CREATE TABLE [User].[CountryRegion](
	[CountryRegionCode] [nvarchar](3) NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_CountryRegion_CountryRegionCode] PRIMARY KEY CLUSTERED 
(
	[CountryRegionCode] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [User].[EmailAddressMap]    Script Date: 07/10/2013 18:50:14 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[EmailAddressMap]') AND type in (N'U'))
DROP TABLE [User].[EmailAddressMap]
GO
CREATE TABLE [User].[EmailAddressMap](
	[OwnerID] [int] NOT NULL,
	[EmailAddressID] [int] IDENTITY(1,1) NOT NULL,
	[EmailAddress] [nvarchar](50) NULL,
 CONSTRAINT [PK_EmailAddressMap_OwnerID_EmailAddressID] PRIMARY KEY CLUSTERED 
(
	[OwnerID] ASC,
	[EmailAddressID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [User].[Password]    Script Date: 07/10/2013 18:50:51 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[Password]') AND type in (N'U'))
DROP TABLE [User].[Password]
GO
CREATE TABLE [User].[Password](
	[LoginID] [nvarchar](10) NOT NULL,
	[PasswordHash] [varchar](128) NOT NULL,
	[PasswordSalt] [varchar](10) NOT NULL,
 CONSTRAINT [PK_Password_OwnerID] PRIMARY KEY CLUSTERED 
(
	[LoginID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [User].[Person]    Script Date: 07/10/2013 18:51:09 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[Person]') AND type in (N'U'))
DROP TABLE [User].[Person]
GO
CREATE TABLE [User].[Person](
	[PersonID] int IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[NameStyle] [bit] NOT NULL,
	[Title] [nvarchar](8) NULL,
	[FirstName] [nvarchar](50) NOT NULL,
	[MiddleName] [nvarchar](50) NULL,
	[LastName] [nvarchar](50) NOT NULL,
	[Suffix] [nvarchar](10) NULL,
	[EmailPromotion] [int] NOT NULL,
 CONSTRAINT [PK_Person_PersonID] PRIMARY KEY CLUSTERED 
(
	[PersonID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [User].[PhoneNumberMap]    Script Date: 07/10/2013 18:51:27 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[PhoneNumberMap]') AND type in (N'U'))
DROP TABLE [User].[PhoneNumberMap]
GO
CREATE TABLE [User].[PhoneNumberMap](
	[OwnerID] [int] NOT NULL,
	[PhoneNumber] [nvarchar](25) NOT NULL,
	[PhoneNumberTypeID] [int] NOT NULL,
 CONSTRAINT [PK_PhoneNumberMap_OwnerID_PhoneNumber_PhoneNumberTypeID] PRIMARY KEY CLUSTERED 
(
	[OwnerID] ASC,
	[PhoneNumberTypeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [User].[PhoneNumberType]    Script Date: 07/10/2013 18:51:46 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[PhoneNumberType]') AND type in (N'U'))
DROP TABLE [User].[PhoneNumberType]
GO
CREATE TABLE [User].[PhoneNumberType](
	[PhoneNumberTypeID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_PhoneNumberType_PhoneNumberTypeID] PRIMARY KEY CLUSTERED 
(
	[PhoneNumberTypeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [User].[StateProvince]    Script Date: 07/10/2013 18:52:02 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[StateProvince]') AND type in (N'U'))
DROP TABLE [User].[StateProvince]
GO
CREATE TABLE [User].[StateProvince](
	[StateProvinceID] [int] IDENTITY(1,1) NOT NULL,
	[StateProvinceCode] [nvarchar](3) NOT NULL,
	[CountryRegionCode] [nvarchar](3) NOT NULL,
	[IsOnlyStateProvinceFlag] [bit] NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_StateProvince_StateProvinceID] PRIMARY KEY CLUSTERED 
(
	[StateProvinceID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object:  Table [User].[Group]    Script Date: 07/10/2013 18:49:14 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[Group]') AND type in (N'U'))
DROP TABLE [User].[Group]
GO
CREATE TABLE [User].[Group](
	[GroupID] [int] IDENTITY(1,1) NOT NULL,
	[GroupName] [nvarchar](50) NOT NULL,
	[ContactPersonID] [int] NOT NULL,
 CONSTRAINT [PK_Group_GroupID] PRIMARY KEY CLUSTERED 
(
	[GroupID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object:  Table [User].[Role]    Script Date: 07/10/2013 18:49:14 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[Role]') AND type in (N'U'))
DROP TABLE [User].[Role]
GO
CREATE TABLE [User].[Role](
	[RoleID] [int] IDENTITY(1,1) NOT NULL,
	[RoleName] [nchar](2) NOT NULL,
	[RoleDesc] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_Role_RoleID] PRIMARY KEY CLUSTERED 
(
	[RoleID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object:  Table [User].[Account]    Script Date: 07/10/2013 18:49:14 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[User].[Account]') AND type in (N'U'))
DROP TABLE [User].[Account]
GO
CREATE TABLE [User].[Account](
	[LoginID] [nvarchar](10) NOT NULL,
	[UserID] [int] NOT NULL,
	[RoleID] [int] NOT NULL,
	[UserType] [nchar](2) NOT NULL,
 CONSTRAINT [PK_Account_LoginID] PRIMARY KEY CLUSTERED 
(
	[LoginID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO